<template>
  <div class="tab-control">
    <div class="tab-control-item"
         v-for="(item, i) in title"
         :key="i">
      <span :class="{active: i === currentIndex}"
            @click="itemClick(i)">{{item}}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: "TabControl",
  props: ['title'],
  data () {
    return {
      currentIndex: 0 //当前活跃状态的索引值
    }
  },
  methods: {
    itemClick (index) {
      this.currentIndex = index;
      //把index传给Home组件
      this.$emit('tabIndex', index);
    }
  }
}
</script>

<style lang="less" scoped>
.tab-control {
  display: flex;
  text-align: center;
  height: 44px;
  line-height: 44px;

  .tab-control-item {
    flex: 1;
  }
}

.active {
  color: var(--color-high-text);
  border-bottom: 3px solid var(--color-high-text);
  padding: 5px;
}
</style>